slicethread: Limit the automatic number of threads to 16
authorMartin Storsjö <martin@martin.st>
Mon, 5 Sep 2022 12:17:56 +0000 (15:17 +0300)
committerSebastian Ramacher <sramacher@debian.org>
Fri, 16 Sep 2022 21:50:22 +0000 (22:50 +0100)
This matches a similar cap on the number of automatic threads
in libavcodec/pthread_slice.c.

On systems with lots of cores, this fixes a couple fate failures
in 32 bit mode on such machines (where spawning a huge number of
threads runs out of address space).

Signed-off-by: Martin Storsjö <martin@martin.st>
Gbp-Pq: Name 0002-slicethread-Limit-the-automatic-number-of-threads-to.patch

libavutil/slicethread.c

index ea1c9c83111b9822cf234b2d846435904b05116f..115b0997369921bfb986c3af3f9f02f96bcf77f2 100644 (file)
@@ -24,6 +24,8 @@
 #include "thread.h"
 #include "avassert.h"
 
+#define MAX_AUTO_THREADS 16
+
 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
 
 typedef struct WorkerContext {
@@ -105,7 +107,7 @@ int avpriv_slicethread_create(AVSliceThread **pctx, void *priv,
     if (!nb_threads) {
         int nb_cpus = av_cpu_count();
         if (nb_cpus > 1)
-            nb_threads = nb_cpus + 1;
+            nb_threads = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS);
         else
             nb_threads = 1;
     }